-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the rust hyper client Send
so it can be used in rust threads more easily
#19207
Conversation
This is follows the lead of the rust hyper server generator and provides an externCrateName. This is because the crate name used for importing can be different from the package name, because dashes `-` get converted to underscores `_`. This allows us to write example code in rustdoc that compiles successfully.
http://petstore.swagger.io/v2 is 301 redirecting to https://petstore.swagger.io/v2 and this is breaking posts to the API. When the client recieves a redirect it does not resend the POST data, instead it switches to GET. This is in line with how browsers behave when encountering a 301 redirect on a POST request.
efbf445
to
31c6a3b
Compare
Send
so it can be used in rust threadsSend
so it can be used in rust threads more easily
@Setter protected String packageVersion = "1.0.0"; | ||
protected String apiDocPath = "docs/"; | ||
protected String modelDocPath = "docs/"; | ||
protected String apiFolder = "src/apis"; | ||
protected String modelFolder = "src/models"; | ||
private String externCrateName = "openapi"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of adding another variable, what about simply create an function called getCrateName()
and we can keep the @Setter above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Why add more state. I was just blindly copying from the rust server code gen.
Updated in the latest commit: 5f8bda3
This trait is also helpful in making the api work well with threads.
93a6df5
to
5f8bda3
Compare
Added one more small commit fa413b4 that makes the api structs |
thanks for the PR. Is it correct to say that this PR is a breaking change? (we do allow breaking changes but need to roll out carefully) |
I'd imagine if the user is just importing But if they were importing the different traits and implementing the So it's technically not backwards compatible. Though maybe backwards compatible for the most common expected use cases?
|
Oh. I guess it's to mask the generic parameters for the individual api structs by wrapping them in |
can you please resolve the merge conflicts when you've time? i'll try to get it merged for the upcoming release |
@@ -1,6 +1,6 @@ | |||
openapi: 3.0.0 | |||
servers: | |||
- url: 'http://petstore.swagger.io/v2' | |||
- url: 'https://petstore.swagger.io/v2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert the change.
the petstore server should be run locally per https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#how-to-add-integration-tests-for-new-petstore-samples
merged via #19375 (tested locally with local petstore server) thanks again for the PR |
Thanks! Sorry I didn't have time to swing back to it! |
The hyper client cannot be used easily in threads as it isn't
Send
friendly. Something like this will fail to compile:Issue with more detailed steps to reproduce: #19208
This PR makes the hyper client and its internals
Send
. So the client can be used in threads.It ended up being a little larger of a PR in the pursuit of writing a test. It turns out the tests aren't actually being run when invoking verify on the petstore samples. This PR had to touch a few other thing to ensure
cargo test
would work. Let me know if I should break it up into multiple PRs.Should I update the pom.xml file to do a
cargo test
instead of acargo check
? I'm not sure if that was intentional.Commit summary
This might be a good order to review the changes:
7ee4bca - This is the commit that actually makes the code work in threads. I adds the
Send
constraint to a bunch generic parameters and traits and uses anArc
instead of anRc
bda9b6d - This commit adds a test to validate that it works and doesn't regress.
e53c04c - This commit regenerates the samples
The remaining commits were trying to get the tests to run in
samples/client/others/rust/
to run successfully. There were several issues to fix to get tests to run successfully.43ba4f0 46d3520 These set it up so the doc strings are compilable. The first one adds a property called
externCrateName
cribbing from the rust-server generator. The second one uses the externCrateName and fixes other issues with the example rustdoc examples.ddb330c The reqwest tests were not compiling and needed a small change.
efbf445 This changes the petstore swagger file and generates the petstore tests to use https. http://petstore.swagger.io/v2 is 301 redirecting to https://petstore.swagger.io/v2 and this is breaking POSTS.
When the client recieves a redirect it does not resend the POST data, instead it switches to GET. This is in line with how browsers behave when encountering a 301 redirect on a POST request, so I wouldn't consider it a bug in the client, but instead a bug in the test code.
Pinging the rust technical committee members: @frol @farcaller @richardwhiuk @paladinzh @jacob-pro
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)